<template>
    <div class="login">
        <div class="class_img">
            <img class="by_img" src="../../static/homeIndex.png" alt srcset />
        </div>
        <div @click="gogetHospital" class="login_h_size">{{hospital.name ||''}}</div>
        <div class="login_btn">
            <button
                class="login_btn_t"
                @getphonenumber="mygetPhoneNumber"
                open-type="getPhoneNumber"
            >微信登录</button>
            <button v-if="1" class="login_btn_o" @click="otherLoginWay">其他方式登录</button>
        </div>
        <div class="login_ck">
            <span @click="go">已阅读并同意《微语医疗用户协议》</span>
        </div>
    </div>
</template>

<script>
export default {
    data() {
        return {
            hospital: {},
            username: "",
            password: "",
            userInfo: {},
            iv: "",
            code: "",
            encryptedData: "",
            item: {
                name: "12312",
                checked: true
            }
        };
    },
    onLoad(option) {
        var _this = this;
        if (option.id) {
             uni.setStorage({
                //存储到本地
                key: "hospital",
                data: option
            });
        }

        uni.getStorage({
            key: "hospital",
            success: function(res) {
                _this.hospital = res.data;
            }
        });
    },
    mounted() {},

    methods: {
        otherLoginWay() {
            uni.navigateTo({
                url: "loginO",
                animationType: "pop-in",
                animationDuration: 200
            });
        },
        go() {
            uni.navigateTo({
                url: "docx",
                animationType: "pop-in",
                animationDuration: 200
            });
        },
        getGpregnant() {
            var _this = this;
            _this.$ajaxs
                .get("/mobile/v1/pregnant/getGpregnant")
                .then(res => {
                    if (!res.content) {
                        uni.showToast({
                            title: "登录成功"
                        });
                        _this.handleLogin();
                    } else {
                        uni.showToast({
                            title: "登录成功"
                        });
                        _this.handleLogin();
                    }
                })
                .catch(err => reject(err));
        },
        handleClick(data) {
            var _this = this;
            this.$ajaxs
                .get("/mobile/v1/wechat/wechatLoginForMini", data)
                .then(res => {
                    if (res.status === 200) {
                        uni.setStorage({
                            //存储到本地
                            key: "token",
                            data: res.content
                        });
                        // _this.getGpregnant();
                        uni.showToast({
                            title: "登录成功"
                        });
                        _this.handleLogin();
                    } else {
                        uni.showToast({
                            title: res.message,
                            icon: "none"
                        });
                        return false;
                    }
                });
        },
        handleLogin() {
            var _this = this;
             uni.getStorage({
                key: "openid",
                success: function(res) {
                    if (res.data) {
                        uni.reLaunch({
                            url: "../index/index"
                        });
                    }
                },
                fail: function(er) {
                    uni.reLaunch({
                        url: "../login/getcode"
                    });
                },
            });
            
            
            
        },
        gogetHospital() {
            uni.navigateTo({
                url: "getHospital"
            });
        },
        namefunder(e) {
            this.username = e.mp.detail.detail.value;
        },
        onGotUserInfo(itm) {},
        mygetPhoneNumber(e) {
            if (!this.item.checked) {
                return uni.showToast({
                    title: "请先阅读并同意用户协议！",
                    icon: "none"
                });
            }
            if (e.mp.detail.encryptedData) {
                uni.login({
                    success: restt => {
                        uni.login({
                            success: rest => {
                                this.code = rest.code;
                                this.encryptedData = e.mp.detail.encryptedData;
                                this.iv = e.mp.detail.iv;
                                var date = {
                                    code: this.code,
                                    encryptedData: this.encryptedData,
                                    iv: this.iv,
                                    audience: "MINIAPP_INNER"
                                };
                                this.handleClick(date);
                            }
                        });
                    }
                });
            }
        },
        wordfunder(e) {
            this.password = e.mp.detail.detail.value;
        },
    }
};
</script>

<style>
.card {
    padding: 20upx;
}
.login {
    height: 100%;
    width: 100%;
    font-family: PingFang-SC-Medium;
}
.col-class {
    margin-bottom: 40upx;
}
.icimgs {
    height: 200upx;
    width: 200upx;
    border-radius: 50%;
    margin: 0 auto;
}
.login_h_size {
    height: 44upx;
    width: 376upx;
    margin: 30upx 0;
    font-size: 32upx;
    color: #fa4d93;
    line-height: 44upx;
    padding-left: 146upx;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    position: relative;
}
.login_h_size:after {
    content: " ";
    display: inline-block;
    height: 15upx;
    width: 15upx;
    border-width: 4upx 4upx 0 0;
    border-color: #fa4d93;
    border-style: solid;
    -webkit-transform: matrix(0.71, 0.71, -0.71, 0.71, 0, 0);
    transform: matrix(0.71, 0.71, -0.71, 0.71, 0, 0);

    position: absolute;
    top: 50%;
    margin-top: -7upx;
    right: 4upx;
}
.imgcenter {
    text-align: center;
    margin-bottom: 80upx;
}
.class_img {
    padding: 126upx 80upx 60upx 80upx;
    text-align: center;
}
.class_img .by_img {
    width: 602upx;
    min-height: 488upx;
}
.login_btn {
    padding: 0 128upx 20upx 128upx;
}
.login_btn .login_btn_t,
.login_btn_o {
    height: 80upx;
    background: rgba(255, 255, 255, 1);
    border-radius: 40upx;
    border: 1upx solid rgba(247, 81, 147, 1);
    font-size: 32upx;
    font-weight: 500;
    color: rgba(247, 81, 147, 1);
}
.login_btn_o {
    margin-top: 18upx;
}
.login_ck {
    height: 34upx;
    font-size: 24upx;
    font-weight: 500;
    color: rgba(153, 153, 153, 1);
    line-height: 34upx;
    text-align: center;
}
.login_ck .checks {
    font-size: 40upx;
}
</style>